import random

class ListNode(object):
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

class LinkedListGenerator:
    """链表数据生成器"""
    
    @staticmethod
    def create_list(values):
        """根据数组创建链表"""
        if not values:
            return None
        
        head = ListNode(values[0])
        curr = head
        for val in values[1:]:
            curr.next = ListNode(val)
            curr = curr.next
        return head
    
    @staticmethod
    def list_to_array(head):
        """链表转数组"""
        result = []
        while head:
            result.append(head.val)
            head = head.next
        return result
    
    @staticmethod
    def get_test_cases():
        """获取测试用例"""
        return [
            # 基础用例
            ([4, 2, 1, 3], "示例1"),
            ([-1, 5, 3, 4, 0], "示例2"),
            ([], "空链表"),
            ([1], "单节点"),
            ([2, 1], "两节点"),
            
            # 特殊情况
            ([1, 1, 1], "重复元素"),
            ([1, 2, 3, 4], "已排序"),
            ([4, 3, 2, 1], "逆序"),
            ([5, 1, 3, 1, 2], "混合重复"),
        ]
    
    @staticmethod
    def generate_random(length, min_val=-50, max_val=50):
        """生成随机数组"""
        return [random.randint(min_val, max_val) for _ in range(length)]
